﻿using System.Diagnostics;

Console.WriteLine("Cores count:" + Environment.ProcessorCount);
Console.WriteLine("Main thread's ID:" + Thread.CurrentThread.ManagedThreadId);

Thread t1 = new Thread(() => PrintPluses(30));
Thread t2 = new Thread(() => PrintMinuses(30));

t1.Start();
t2.Start();

Task taskOne = Task.Run(() => PrintPluses(200));
Task taskTwo = Task.Run(() => PrintMinuses(200));



Stopwatch stopwatch = Stopwatch.StartNew();
for (int i = 0; i < 100; i++)
{
    ThreadPool.QueueUserWorkItem(PrintA);
}

stopwatch.Stop();
Console.WriteLine("Took:" + stopwatch.ElapsedMilliseconds);

Task<int> taskWithResult = Task.Run(() => CalculateLength("hello world"));






Console.ReadKey();

static int CalculateLength(string input)
{
    Console.WriteLine("CalculateLength thread's ID:" + Thread.CurrentThread.ManagedThreadId);
    Thread.Sleep(2000);
    return input.Length;
}



static void PrintA(object obj)
{
    Console.Write("A");
}

static void PrintPluses(int n)
{
    Console.WriteLine("\nPrintPluses thread's ID:" + Thread.CurrentThread.ManagedThreadId);

    for (int i = 0; i < n; i++)
    {
        Console.WriteLine("+");
    }
}

static void PrintMinuses(int n)
{
    Console.WriteLine("\nPrintMinuses thread's ID:" + Thread.CurrentThread.ManagedThreadId);

    for (int i = 0; i < n; i++)
    {
        Console.WriteLine("-");
    }
}